package logic

import (
	"context"
	"goods_srv/goodsclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCartLogic {
	return &AddCartLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddCartLogic) AddCart(req *types.AddCartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	goods, err := l.svcCtx.GoodsSrv.AddCart(l.ctx, &goodsclient.AddCartRequest{
		UserId:   int64(req.UserId),
		GoodsId:  int64(req.GoodsId),
		GoodsNum: int64(req.GoodsNum),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加购物车成功",
		Code:    200,
		Data:    goods,
	}, nil

}
